
#include <windows.h>
#include <iostream>
#include <cmath>

using namespace std;

#include "GMachine.h"
#include "GFunction.h"
using namespace GMachine;

int main()
{
	REGISTER_PERFCOUNTER("GMachine Perf Test");

	try
	{
		GProcessor prc;

		FunctionObject obj4 = ExportFunction(&floor);


		DWORD timeduration = 0;
		{
			prc.reg.F[1] = 182.334;
			prc.stk.Push(Regname::F0);
			prc.stk.Push(Regname::F1);
			//prc.stk.Push(182.334);
			PERFCOUNTER("invoke call");
			timeduration = GetTickCount();
			for (int i = 0; i < 10000000; i++)
			{
				PERFCOUNTER("invoke call----");
				obj4.Invoke(prc.stk, prc.reg);
			}
			timeduration = GetTickCount() - timeduration;
			cout<<"used time: "<<timeduration<<" ms."<<endl;
			cout<<" result:"<<prc.reg.F[0]<<endl;
		}

		unsigned char buffer[] = {
			Codename::floor, (char)(Regname::F4.regid), 0xA6, 0x9B, 0xC4, 0x20, 0xB0, 0xCA, 0x66, 0x40,
		};


		{
			PERFCOUNTER("process codes");
			timeduration = GetTickCount();
			for (int i = 0; i < 10000000; i++)
			{
				PERFCOUNTER("process codes----");
				prc.Process(buffer, sizeof(buffer));
			}
			timeduration = GetTickCount() - timeduration;
			cout<<"used time: "<<timeduration<<" ms."<<endl;
			cout<<" result:"<<prc.reg.F[4]<<endl;
		}

		{
			PERFCOUNTER("direct call");
			timeduration = GetTickCount();
			for (int i = 0; i < 10000000; i++)
			{
				PERFCOUNTER("direct call----");
				//MyTest3(234234, 9459894);
				floor(182.334);
			}
			timeduration = GetTickCount() - timeduration;
			cout<<"used time: "<<timeduration<<" ms."<<endl;
			cout<<" result:"<<floor(182.334)<<endl;
		}
	}
	catch(...)
	{
		cout<<"exception occured."<<endl;
	}

	return 0;
}
//=======================================================================
//#include <iostream>
//#include "GUtility.h"
//
//using namespace std;
//using namespace GMachine;
//
//class A {};
//
//class B {public: A a; };
//
//class C {public: B b; class M{}; };
//
//
//typedef const volatile C ** const ** volatile *** D;
//
//typedef const A * E;
//
//typedef const A CA;
//
//
//int main()
//{
//	CompileTimeAssert<false>;
//	cout<<typeid(CA).name()<<endl;
//	cout<<typeid(TypeTraits<E>::Class).name()<<endl;
//	cout<<"model ID of E class:"<<TypeTraits<TypeTraits<E>::Class>::ModelId<<endl;
//	cout<<typeid(TypeTraits<E>::ConstClass).name()<<endl;
//	cout<<"model ID of E ConstClass:"<<TypeTraits<TypeTraits<E>::ConstClass>::ModelId<<endl;
//	cout<<typeid(TypeTraits<E>::VolatileClass).name()<<endl;
//	cout<<"model ID of E VolatileClass:"<<TypeTraits<TypeTraits<E>::VolatileClass>::ModelId<<endl;
//	cout<<typeid(TypeTraits<E>::ConstVolatileClass).name()<<endl;
//	cout<<"model ID of E ConstVolatileClass:"<<TypeTraits<TypeTraits<E>::ConstVolatileClass>::ModelId<<endl;
//	cout<<typeid(TypeTraits<E>::Pointer).name()<<endl;
//	cout<<"model ID of E Pointer:"<<TypeTraits<TypeTraits<E>::Pointer>::ModelId<<endl;
//	cout<<typeid(TypeTraits<E>::ConstPointer).name()<<endl;
//	cout<<"model ID of E ConstPointer:"<<TypeTraits<TypeTraits<E>::ConstPointer>::ModelId<<endl;
//	cout<<typeid(TypeTraits<E>::VolatilePointer).name()<<endl;
//	cout<<"model ID of E VolatilePointer:"<<TypeTraits<TypeTraits<E>::VolatilePointer>::ModelId<<endl;
//	cout<<typeid(TypeTraits<E>::ConstVolatilePointer).name()<<endl;
//	cout<<"model ID of E ConstVolatilePointer:"<<TypeTraits<TypeTraits<E>::ConstVolatilePointer>::ModelId<<endl;
//	cout<<typeid(TypeTraits<E>::Reference).name()<<endl;
//	cout<<"model ID of E Reference:"<<TypeTraits<TypeTraits<E>::Reference>::ModelId<<endl;
//	cout<<typeid(TypeTraits<E>::ConstReference).name()<<endl;
//	cout<<"model ID of E ConstReference:"<<TypeTraits<TypeTraits<E>::ConstReference>::ModelId<<endl;
//	cout<<typeid(TypeTraits<E>::VolatileReference).name()<<endl;
//	cout<<"model ID of E VolatileReference:"<<TypeTraits<TypeTraits<E>::VolatileReference>::ModelId<<endl;
//	cout<<typeid(TypeTraits<E>::ConstVolatileReference).name()<<endl;
//	cout<<"model ID of E ConstVolatileReference:"<<TypeTraits<TypeTraits<E>::ConstVolatileReference>::ModelId<<endl;
//	cout<<"-----------------------------------"<<endl;
//	cout<<typeid(D).name()<<endl;
//	cout<<typeid(TypeTraits<D>::Class).name()<<endl;
//	cout<<typeid(TypeTraits<TypeTraits<D>::Class>::Class).name()<<endl;
//	cout<<typeid(TypeTraits<TypeTraits<TypeTraits<D>::Class>::Class>::Class).name()<<endl;
//	cout<<typeid(TypeTraits<D>::NativeClass).name()<<" native D model ID:"<<TypeTraits<TypeTraits<D>::NativeClass>::ModelId<<endl;
//
//	return 0;
//}

//TypeExtraction<E>::
//TypeExtraction<E>::length



bool MyTest(int & a, int b, int * result)
{
	*result = a*b;
	return a+b != 0;
	//printf("a=%d, b=%d\n", a, b);
}
/*
msgbox.put<id>(100);
msgbox.put<id>(110, ALL);
msgbox.put<id>(111, 10);
msgbox.clr<id>();
msgbox.put<id>(1, 1);
msgbox.put<str>("asdasd");
msgbox.get<str>();
msgbox.get<str>(=="jiajis");


box msgbox
{
	int id();
	std::string str();
};

if (msgbox.get<id>(100))
{
}
int id = msgbox.get<id>();
int id = msgbox.get<id>(>100);
int id = msgbox.get<id>(<100);
int id = msgbox.get<id>(!=100);
int id = msgbox.get<id>(==100);
int id = msgbox.get<id>(<=100);



box text
{
	int ch;
};

text mytext;

for (;;)
{
	int ch = mytext.get<ch>();
	printf("%c", ch);
}
*/

